package com.dingup.mock.handler;


import com.dingup.mock.enums.ExamContentTypeEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by yanggavin on 16/5/24.
 */
public class ExamContentTypeEnumHandler extends BaseTypeHandler<ExamContentTypeEnum> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, ExamContentTypeEnum parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, parameter.getCode());
    }

    @Override
    public ExamContentTypeEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return ExamContentTypeEnum.valueOf(rs.getString(columnName).toUpperCase());
    }

    @Override
    public ExamContentTypeEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return ExamContentTypeEnum.valueOf(rs.getString(columnIndex).toUpperCase());
    }

    @Override
    public ExamContentTypeEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return ExamContentTypeEnum.valueOf(cs.getString(columnIndex).toUpperCase());
    }
}
